package wangmin.message.mgr_web.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import wangmin.message.mgr_web.web.entity.CommonResponseBody;
import wangmin.message.mgr_web.web.entity.type.CommonResponseCode;
import wangmin.message.mgr_web.web.service.AuthService;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>User: Wang Min
 * <p>Date: 2016-12-19
 * <p>Version: 1.0
 */
@Controller
@Api(description = "登录的相关操作")
public class LoginController {
    @Autowired
    private AuthService authService;

	@RequestMapping(value = "/loginPage", method = {RequestMethod.GET,RequestMethod.POST})
    @ApiOperation(value = "登页录")
    public String loginPage() {
        return "loginPage";
    }

    @RequestMapping(value = "/user/login", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    @ApiOperation(value = "用户登录")
    public CommonResponseBody userLogin(String userName, String userPassword, HttpServletRequest request) {
        if (authService.userLogin(userName, userPassword, request)) {
            return new CommonResponseBody();
        } else {
            return new CommonResponseBody(CommonResponseCode.permissionError, "用户名或密码错误");
        }
    }
}
